package sortieren;

public class Sort {
	public static void main(String[] args) {

		int[] array = { 3, 4, 5, 6, 2, 3, -4, 2, 2, 42, 3 };
		
		// Sortieren
		for(int i = 1; i < array.length; i++) {
			for(int j = array.length - 1; j >= i; j--) {
				if (array[j] < array[j - 1]) {
					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
				}
			}
		}

		// Sortierte Liste ausgeben
		for(int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
		
		System.out.println();
		System.out.println();
		
		
		// Zeidimensionales Array sortieren
		String[][] feld = new String [5][2];
		feld[0][0] = "Johann";
		feld[0][1] = "4";
		feld[1][0] = "Olli";
		feld[1][1] = "5";
		feld[2][0] = "Hans";
		feld[2][1] = "1";
		feld[3][0] = "Flo";
		feld[3][1] = "4";
		feld[4][0] = "Klaus";
		feld[4][1] = "2";
		
		// Sortieren
		for(int i = 1; i < feld.length; i++)
		{
			for(int j = feld.length - 1; j >= i; j--)
			{
				if (Double.parseDouble(feld[j][1]) > Double.parseDouble(feld[j - 1][1]))
				{
					String[][] temp = new String[1][2];
					temp[0][0] = feld[j][0];
					temp[0][1] = feld[j][1];
					feld[j][0] = feld[j-1][0];
					feld[j][1] = feld[j-1][1];
					feld[j-1][0] = temp[0][0];
					feld[j-1][1] = temp[0][1];
				}
			}
		}		
		
		// Ausgabe
		for(int i = 0; i<feld.length; i++)
		{
			for(int j = 0; j<feld[j].length; j++)
			{
				System.out.println(feld[i][j]);
			}
			System.out.println();
		}
	}
}